"use strict";
/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.createTable("Users", {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER.UNSIGNED,
        comment: "用户ID",
      },
      username: {
        allowNull: false,
        type: Sequelize.STRING(45),
        comment: "用户名，用于登陆",
      },
      fullName: {
        type: Sequelize.STRING(20),
        comment: "用户名字",
      },
      password: {
        allowNull: false,
        type: Sequelize.STRING,
        comment: "用户密码",
      },
      phone: {
        allowNull: false,
        type: Sequelize.STRING(20),
        comment: "用户手机号，用于登陆",
      },
      email: {
        type: Sequelize.STRING,
        comment: "用户邮箱，用于登陆",
      },
      avatar: {
        type: Sequelize.STRING,
        comment: "用户头像",
      },
      gender: {
        defaultValue: 3,
        type: Sequelize.TINYINT,
        comment: "用户性别，3：未知，1：男，2：女",
      },
      status: {
        defaultValue: false,
        allowNull: false,
        type: Sequelize.BOOLEAN,
        comment: "用户状态，是否启用",
      },
      isDelete: {
        defaultValue: false,
        type: Sequelize.BOOLEAN,
        comment: "用户是否已经删除",
      },
      createdAt: {
        allowNull: false,
        type: Sequelize.DATE,
        comment: "创建时间",
      },
      updatedAt: {
        allowNull: false,
        type: Sequelize.DATE,
        comment: "更新时间",
      },
    });
    await queryInterface.addIndex("Users", {
      fields: ["username"],
      unique: true,
    });
    await queryInterface.addIndex("Users", {
      fields: ["phone"],
      unique: true,
    });
    await queryInterface.addIndex("Users", {
      fields: ["email"],
      unique: true,
    });
  },
  async down(queryInterface, Sequelize) {
    await queryInterface.dropTable("Users");
  },
};
